home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / reform16.zip / REFORMAT.PAS < prev    next >
Pascal/Delphi Source File  |  1990-03-03  |  24KB  |  708 lines

  1. {
  2. To:  INFO-IBMPC-REQUEST@USC-ISIB.ARPA
  3. From:  U001222%HNYKUN11.BITNET@WISCVM.WISC.EDU
  4. Subject: reformat.pas
  5. }
  6. PROGRAM reformat;
  7. {
  8.   Program to reformat any disk attached to an Olivetti PC or compatible.
  9.   The progam will work well on any MS/PC-DOS machine running under DOS
  10.   versions 2.00 up to and including 3.10. Fixed disks up to 32 Meg.
  11.  
  12.     V1.50 Extensions made for big FATs. WORD.INC included for handling of
  13.     word integers. MS-DOS function INT21 / 32H used for drive information.
  14.     Corrected the problem of DOS losing track of the current directory.
  15.  
  16.     The program has been tested under DOS 2.00 thru 3.10
  17.     It will probably work under DOS 3.20 too, but this version will not
  18.     run when you try to do so. If you want to test it with DOS 3.20, look
  19.     for the string DOS_Versions (it's somewhere near the end of the program)
  20.     in this program, and include that version number into the test.
  21.     Please let the author know whether you had success or not.
  22.  
  23.     Jos Wennmacker                                    July 86.
  24.     Universitair Rekencentrum
  25.     Geert Grooteplein Zuid 41
  26.     6525 GA Nijmegen
  27.     The Netherlands
  28.  
  29.     BITNET address: U015415 at HNYKUN22
  30.  
  31.     v1.6, 23 Nov 89  David Kirschbaum, Toad Hall
  32.     - Recoded for TP v5.0
  33.  
  34.  
  35.     V1.5  Jos added new 16-bit and word code, handling up to 30Meg
  36.     hard disks, etc.  I cleaned up the integer math inline procedures
  37.     a little.
  38.     David Kirschbaum, Toad Hall
  39.  
  40.     V1.23 Added FRAMER.INC, WRITEF.INC for framing, fast screen write,
  41.     fast screen line clear.  Tightened up displays a little.
  42.     This version is now VERY PC-specific.  Generic MS-DOS functions
  43.     for screen stuff to follow.
  44.     David Kirschbaum, Toad Hall.
  45.  
  46.     V1.22 Added inline code to replace the INT25.ASM and INT26.ASM
  47.     files.
  48.     David Kirschbaum, Toad Hall, 3 May 86
  49.  
  50.     V1.21(mod) not publicly released. Changes made by Rick Watson to let
  51.     the program recognize the big (16 bit) FATs. He made it run on 20 Meggers
  52.     under DOS 3.x. Martin Hobson made it run on 30 Meggers under DOS 3.x.
  53.     May 86.
  54.  
  55.     V1.21 Small corrections made to avoid Turbo integer overflow. (Hey,
  56.     Borland, what about a WORD type in Turbo, would be very usefull using
  57.     the MSDOS features!).
  58.  
  59.     V1.20 First release to the public domain.
  60.     What started as a favour to a friend grew into a nice program.
  61.     Do you like it? Let me know about it! If I know many people to use it,
  62.     I'll keep it up to date, and send you new releases.
  63.     Jos Wennmacker
  64.  
  65. }
  66. {$A+}         {word alignment to be nice}
  67. {$B-}         {short-circuit Boolean Eval}
  68. {$D-}         {no debug}
  69. {$F-}         {no far calls}
  70. {$L-}         {no local information}
  71. {$R-}         {no range checking}
  72. {$S-}         {no stack checking}
  73. {$V-}         {no string checking}
  74.  
  75. Uses  Dos,Crt;  {v1.6}
  76.  
  77. {-------------------------------- Global types -------------------------------}
  78.  
  79. TYPE
  80.  
  81. {------------------- types for word arithmetic  see REFORMAT.IN1 -------------}
  82.  
  83.   Relational_Operator =      (Eq, Gt, Lt, Ne, Ge, Le);
  84.  
  85.  
  86. {----------------------------- Bootrecord layout -----------------------------}
  87.  
  88.   Boot                =                { the layout of the DOS boot record}
  89.     RECORD
  90.       Jump:                  ARRAY[0..2] OF Byte; { Near jump to boot code}
  91.       OEM :                  ARRAY[0..7] OF CHAR; { eight character OEM name}
  92.       sectorSize:            word;     { number of bytes in one sector}
  93.       clusterSize:           Byte;     { sectors per cluster}
  94.       reservedSectors:       word;     { DOS boot code sector(s) typically 1}
  95.       numberOfFATs:          Byte;     { usually 2, but often 1 for RAM disks}
  96.       rootDirSize,                     { maximum entries in root directory}
  97.       totalSectors:          word;     { total sectors in the logical image}
  98. { A limited description of the drive
  99.   bit 0 = 1: twosided, 0: not two-sided
  100.   bit 1 = 1: 8-sector, 0: not 8-sector
  101.   bit 2 = 1: removable 0: not removable
  102.   bits 3-7 must be set to 1
  103. }
  104.       mediaDescriptor:       Byte;
  105.       fatSize,                         { number of sectors in each FAT copy}
  106.       trackSize,                       { number of sectors per track}
  107.       numberOfHeads,                   { number of heads}
  108. { sectors hidden from DOS, preceding the DOS partition: including the
  109.   master boot record and any non-DOS partitions
  110. }
  111.       hiddenSectors:         word;
  112.     END;
  113.  
  114. {---------------- Layout of DOS function 32h disk parameter block ------------}
  115.  
  116.   Parms_32            =     ^Parameter_table;
  117.  
  118.   Parameter_Table     =                { layout of the DOS function 32 table}
  119.     RECORD
  120.       assignedDisk,                    { 0 = A, 1 = B, ...}
  121.       altAD:                 Byte;     { same as above, but 0 for RAM disk}
  122.       sectorSize:            word;     { number of bytes in one sector}
  123.       clusterSize_1,                   { sectors per cluster minus 1}
  124.       numberOfHeads_1:       Byte;     { number of heads minus 1}
  125.       reservedSectors:       word;     { DOS boot code sector(s) typically 1}
  126.       numberOfFATs:          Byte;     { usually 2, but often 1 for RAM disks}
  127.       rootDirSize,                     { maximum entries in root directory}
  128.       firstDataSector,                 { first sector for data storage}
  129.       totalDataClusters_1:   word;     { total data clusters plus 1}
  130.       fatSize:               Byte;     { number of sectors in each FAT copy}
  131.       firstDirectorySector:  word;     { first sector of the root directory}
  132. (* v1.6
  133.       DeviceDriverAddress:  ^byte;     { Far (offset, segment) address of the
  134.                                          DOS device driver for the drive}
  135. *)
  136.       DeviceDriverAddress:   Pointer;  {v1.6}
  137. { A limited description of the drive
  138.   only the low order byte is used:
  139.   bit 0 = 1: twosided, 0: not two-sided
  140.   bit 1 = 1: 8-sector, 0: not 8-sector
  141.   bit 2 = 1: removable 0: not removable
  142.   bits 3-7 must be set to 1
  143. }
  144.       mediaDescriptor:       word;
  145.       NextParameterTable:    Parms_32; { far pointer to next disk table}
  146. { Starting cluster of current working directory.
  147.   According to Glenn Roberts in his May 86 PC Tech Journal article
  148.   "Finding Disk Parameters" this would only hold for PC DOS 2.00
  149. }
  150.       currentDirCluster:     word;
  151.       CurrentDirName:        ARRAY [0..63] OF CHAR
  152. { The name of the current working directory. This does not hold for
  153.   DOS 3.x versions. Only for 2.00
  154. }
  155.     END;
  156.  
  157. {-------- Long byte and integerarays for Disk Transfer Area, Fats etc. -------}
  158.  
  159.   intArray   = ARRAY[0..32766] OF Word;  {v1.6 INTEGER;}
  160.  
  161.   buffer     = ARRAY[0..32766] OF Byte;
  162.  
  163. {--------------------- Element of tree of directory entries ------------------}
  164.  
  165.   DirectoryPointer = ^DirectoryEntry;
  166.  
  167. (*v1.6  longInteger      = ARRAY[0..1] OF INTEGER; *)
  168.  
  169.   DirectoryEntry =
  170.     RECORD
  171. { name + extension w/o period
  172.   If the first char is $00, then this entry was never used.
  173.   Also the next entries in this directory have never been used.
  174.   If the first char is $E5, then this entry was erased.
  175. }
  176.       EntryName:          ARRAY[0..10] OF CHAR;
  177. { attribute of entry:
  178.   bit      if set means
  179.    0       read only file
  180.    1       hidden file
  181.    2       system file
  182.    3       volume label
  183.    4       subdirectory
  184.    5       archive bit
  185. }
  186.       attribute:          Byte;
  187.       reserved:           ARRAY[1..10] OF Byte; { for future use}
  188. { mapped in the bits:
  189.   <     hh     > <    mm    > <   xx  >
  190.   15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
  191.   where:
  192.   hh  binary number of hours [0..23]
  193.   mm  binary number of minutes [0..59]
  194.   xx  binary number of two-second
  195.       increments [0..28]
  196. }
  197.       timeLastUpdated:    word;
  198. { mapped in the bits
  199.   <        yy       > < mm  > <   dd  >
  200.   15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
  201.   where:
  202.   yy  binary number of years [0..119]
  203.       (1980-2099)
  204.   mm  binary number of month [1..129]
  205.   dd  binary number of day [1..31]
  206. }
  207.       dateLastUpdated:    word;
  208.       startingCluster:    word;        { index of the file's first cluster}
  209.       fileSize: